﻿using System;
using System.Xml.Serialization;

namespace ICalendar.CalendarProperties
{
    /// <summary>
    /// This property defines the overall status or confirmation for the calendar component.
    /// </summary>
    /// <typeparam name="T">This type can be only a EventStatusValue/TodoStatusValue/JournalStatusValue</typeparam>
    [Serializable]
    [XmlRoot("status")]
    public class Status<T> : CalendarPropertyBase<T>
    {
        public Status()
        {
            
        }

        public Status(T status)
            : base(status)
        {
            
        }
        protected override void SetValue(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                //Value = null ;
                Value = default(T);
                return;
            }
            if (value.ToUpperInvariant() == "NEEDS-ACTION")
                value = "NeedsAction";
            Enum.Parse(typeof (EventStatusValue), value, true);
        }

        protected override string GetValue()
        {
            var value = Value.ToString().ToUpperInvariant();
            return value.ToUpperInvariant() == "NEEDSACTION" ? "NEEDS-ACTION" : value;
        }

        protected override void SetParametersFromXParameters(XParameterCollection xparams)
        {
            
        }

        protected override XParameterCollection GetXParametersFromParameters()
        {
            return null;
        }

        protected override string[] GetXReservedParametersNames()
        {
            return null;
        }


        public static implicit operator Status<T>(T value)
        {
            return new Status<T>(value);
        }

    }
}
